/**
 * Created by HaiQi on 2017-3-14.
 */

function SetHMS(f) {
    //度
    var h = parseInt(f);
    //分
    var m = parseInt((parseFloat(f) - parseInt(h)) * 60);
    //秒
    var s = parseInt(((parseFloat(f) - parseInt(h)) * 60 - parseInt(m)) * 60);

    if (m.toString().length == 1) {
        m = '0' + m.toString();
    }
    if (s.toString().length == 1) {
        s = '0' + s.toString();
    }

    var hms = h + '°' + m + '′' + s + '″';
    if ($.trim(h) == "NaN")
        hms = ""
    return hms;
}
var plonlat;
var bkStroke = new ol.style.Stroke({
    color:"red",
    opacity: 1,
    width:2
});
var bkFill = new ol.style.Fill({
    color:"red",
    opacity:0.008
});
var bkPoint = new ol.style.Circle();
var bkLayer = new ol.layer.Vector({
    stroke:stroke,
    fill:fill

});
/*var bkLayer = new OpenLayers.Layer.Vector("bk", {
    styleMap: new OpenLayers.StyleMap({
        'default': {
            strokeColor: "red",
            strokeOpacity: 1,
            strokeWidth: 2,
            strokeDashstyle: "solid",
            fillColor: "red",
            fillOpacity: 0.08,
            pointRadius: 0,
            pointerEvents: "visiblePainted"
        }
    }),
    'SphericalMercator': true,
    displayInLayerSwitcher: false,
    rendererOptions: { zIndexing: true }
});*/
function createRed(lonlat) {
    bkLayer.removeAllFeatures();
    var lon = 0;
    var lat = 0;
    if (lonlat != null) {
        lon = lonlat[0];
        lat = lonlat[1];
        if (map.getZoom() >= 11) {
            var xs = Math.pow(2, map.getZoom() - 11);
            var yspointList = [], yxpointList = [], zspointList = [], zxpointList = [];
            var s5 = 0, s1 = 0;
            if (map.getZoom() >= 11) {
                s5 = 0.005 / xs; s1 = 0.010 / xs;
                //s5 = 0.01 / xs; s1 = 0.020 / xs;
            }

           // ol.geom.Point();
            var ysnewPoint = new  ol.geom.Point([lon + s5, lat + s1]);//new OpenLayers.Geometry.Point(lonlat.lon + s5, lonlat.lat + s1);
            yspointList.push(ysnewPoint);
            ysnewPoint = new ol.geom.Point([lon + s1, lat + s1]);//new OpenLayers.Geometry.Point(lonlat.lon + s1, lonlat.lat + s1);
            yspointList.push(ysnewPoint);
            ysnewPoint = new ol.geom.Point([lon + s1, lat + s5]);//new OpenLayers.Geometry.Point(lonlat.lon + s1, lonlat.lat + s5);
            yspointList.push(ysnewPoint);

            var yxnewPoint = new ol.geom.Point([lon + s5, lat - s1]);//new OpenLayers.Geometry.Point(lonlat.lon + s5, lonlat.lat - s1);
            yxpointList.push(yxnewPoint);
            yxnewPoint = new ol.geom.Point([lon + s1, lat - s1]);//new OpenLayers.Geometry.Point(lonlat.lon + s1, lonlat.lat - s1);
            yxpointList.push(yxnewPoint);
            yxnewPoint = new ol.geom.Point([lon + s1, lat - s5]);//new OpenLayers.Geometry.Point(lonlat.lon + s1, lonlat.lat - s5);
            yxpointList.push(yxnewPoint);

            var zsnewPoint = new ol.geom.Point([lon - s5, lat + s1]);//new OpenLayers.Geometry.Point(lonlat.lon - s5, lonlat.lat + s1);
            zspointList.push(zsnewPoint);
            zsnewPoint =  new ol.geom.Point([lon - s1, lat + s1]);//new OpenLayers.Geometry.Point(lonlat.lon - s1, lonlat.lat + s1);
            zspointList.push(zsnewPoint);
            zsnewPoint = new ol.geom.Point([lon - s1, lat + s5]);//new OpenLayers.Geometry.Point(lonlat.lon - s1, lonlat.lat + s5);
            zspointList.push(zsnewPoint);

            var zxnewPoint = new ol.geom.Point([lon - s5, lat - s1]);//new OpenLayers.Geometry.Point(lonlat.lon - s5, lonlat.lat - s1);
            zxpointList.push(zxnewPoint);
            zxnewPoint = new ol.geom.Point([lon - s5, lat - s1]);//new OpenLayers.Geometry.Point(lonlat.lon - s1, lonlat.lat - s1);
            zxpointList.push(zxnewPoint);
            zxnewPoint = new ol.geom.Point([lon - s1, lat - s5]);//new OpenLayers.Geometry.Point(lonlat.lon - s1, lonlat.lat - s5);
            zxpointList.push(zxnewPoint);

            var yslinestring = new ol.geom.LineString(yspointList); //new OpenLayers.Geometry.LineString(yspointList);
            var yslineFeature = new ol.Feature.Vector(yslinestring);//new OpenLayers.Feature.Vector(yslinestring);
            var yxlinestring = new ol.geom.LineString(yxpointList);//new OpenLayers.Geometry.LineString(yxpointList);
            var yxlineFeature = new ol.Feature.Vector(yxlinestring);//new OpenLayers.Feature.Vector(yxlinestring);
            var zslinestring = new ol.geom.LineString(zspointList);//new OpenLayers.Geometry.LineString(zspointList);
            var zslineFeature = new ol.Feature.Vector(zslinestring);//new OpenLayers.Feature.Vector(zslinestring);
            var zxlinestring = new ol.geom.LineString(zxpointList);//new OpenLayers.Geometry.LineString(zxpointList);
            var zxlineFeature = new ol.Feature.Vector(zxlinestring);//new OpenLayers.Feature.Vector(zxlinestring);
            bkLayer.addFeatures([yslineFeature, yxlineFeature, zslineFeature, zxlineFeature]);
        }
        else
            lonlat = null;
    }
}
